package spring.j2024_11_17_2.wall.controller;


import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
@ResponseBody
@RequestMapping("/user")
public class UserController {
    @RequestMapping("/login")
    public boolean login(String name , String password , HttpSession session){
        if(!StringUtils.hasLength(name) || !StringUtils.hasLength(password)){
            return false ;
        }
        if("zhangsan".equals(name) && "1234".equals(password)){

            session.setAttribute("name",name);
            session.setAttribute("password",password);
            return true ;
        }

        return false ;
    }
    @RequestMapping("/get")
    public String get(HttpSession session){
         String name = (String) session.getAttribute("name");
        return " "+ name ;
    }
}
